package controller;

import BBS.bean.PageInfo;
import service.PageService;
import service.impl.PageServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/page")
public class PageController extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String type = request.getParameter("type");
        if (null == type) {
            response.sendRedirect("page.jsp");
        }
        if ("page".equals(type)) {
            page1(request, response);
        }
    }


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request,response);
    }

    private void page1(HttpServletRequest request, HttpServletResponse response) throws IOException {
        PageService ps = new PageServiceImpl(request.getServletContext());
        List<PageInfo> list = ps.findPageAll();
        request.getSession().setAttribute("PAGES",list);
        response.sendRedirect("page.jsp");
    }


}
